//Page Object
// 获取应用实例
const app = getApp()
import { request } from '../../request/index'
Page({
  data: {
    swiperList: [],
    catList: [],
    floorList: []
  },
  //options(Object)页面开始加载 就会触发
  onLoad: function (options) {
    //发起异步请求 获取轮播图
    // wx.request({
    //   url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
    //   header: {'content-type':'application/json'},
    //   method: 'GET',
    //   dataType: 'json',
    //   responseType: 'text',
    //   success: (res)=>{
    //     console.log(res);
    //     this.setData({
    //       swiperList:res.data.message
    //     })
    //   },
    //   fail: ()=>{},
    //   complete: ()=>{}
    // });
    this.getSwiperList();
    this.getCatItems();
    this.getFloordata();
  },
  //发起异步请求 获取轮播图
  getSwiperList() {
    request({ url: '/home/swiperdata' }).then(res => {
      // console.log(res);
      res.forEach(v => v.navigator_url = v.navigator_url.replace("main", "index"))
      this.setData({
        swiperList: res
      })
    })
  },
  //获取导航
  async getCatItems() {
    const res = await request({ url: '/home/catitems' })
    //console.log(res);
    this.setData({
      catList: res
    })
  },
  //获取楼层
  async getFloordata() {
    const res = await request({ url: '/home/floordata' })
    console.log(res);
    res.forEach(v => v.product_list.forEach(i =>
      i.navigator_url = i.navigator_url.slice(0, 17) + "/index" + i.navigator_url.slice(17)))
    this.setData({
      floorList: res
    })
  },

  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {

  },
  onPageScroll: function () {

  },
  //item(index,pagePath,text)
  onTabItemTap: function (item) {

  }
});